package com.yphone.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yphone.tools.MyLog;

public abstract class BasicFragment extends Fragment {
    private static final String STATE_SAVE_IS_HIDDEN = "STATE_SAVE_IS_HIDDEN";
    protected boolean isCreated = false;
    protected Activity mActivity;

    /* access modifiers changed from: protected */
    public abstract int getLayout();

    /* access modifiers changed from: protected */
    public abstract void initData();

    /* access modifiers changed from: protected */
    public abstract void initListener();

    /* access modifiers changed from: protected */
    public abstract void initView(View view, Bundle bundle);

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
            MyLog.i(BasicFragment.class.getSimpleName(), "classname:" + getClass().getName() + ",isState:" + savedInstanceState.getBoolean(STATE_SAVE_IS_HIDDEN));
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.remove(this);
            ft.commit();
        }
        this.isCreated = true;
    }

    @Nullable
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getLayout(), container, false);
        initView(view, savedInstanceState);
        initListener();
        initData();
        return view;
    }

    public void onAttach(Context context) {
        super.onAttach(context);
        this.mActivity = (Activity) context;
    }

    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        MyLog.i(BasicFragment.class.getSimpleName(), "onSaveInstanceState");
        outState.putBoolean(STATE_SAVE_IS_HIDDEN, isHidden());
    }

    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (this.isCreated) {
            if (isVisibleToUser) {
                performVisibleAction();
            } else {
                performInvisibleAction();
            }
        }
    }

    public void onDestroy() {
        super.onDestroy();
        this.isCreated = false;
    }

    /* access modifiers changed from: protected */
    public void performVisibleAction() {
    }

    /* access modifiers changed from: protected */
    public void performInvisibleAction() {
    }
}